import axios from "axios";
import {useTokenStore} from "@/js/util/token";
const baseURL = "/api"
const instance = axios.create({baseURL})
//添加请求拦截器
instance.interceptors.request.use(
    (config)=>{
        //请求前的回调
        //添加token
        const tokenStore = useTokenStore()
        //判断有没有token
        if(tokenStore.token){
            config.headers.Authorization = tokenStore.token
        }
        return config
    },
    (err) => {
        //请求错误的回调
        Promise.reject(err)
    }
)
//添加响应拦截器
instance.interceptors.response.use()

export default instance